from time import sleep

import page
from base.base import Base
from tool.get_log import GetLogger

log = GetLogger().get_log()


class PageSettings(Base):

    def pageset_click_settings(self):
        self.base_click_element(page.wd_setting)

    def pageset_click_person(self):
        self.base_click_element(page.setting_person)

    def pageset_click_push(self):
        self.base_click_element(page.setting_notice)

    def pageset_click_clear_cache(self):
        self.base_click_element(page.setting_clear_cache)

    def pageset_click_change_touxiang(self):
        self.base_click_element(page.person_change_touxiang)

    def pageset_click_select_touxiang_from_album(self):
        self.base_click_element(page.person_select_touxiang_from_album)


    def pageset_click_select_agree(self):
        try:
            # sleep(2)
            self.base_click_element(page.right_next_step)
        except:
            pass
        self.base_click_element(page.person_select_allow_btn)

    def pageset_select_first_img(self):
        self.base_click_element(page.person_first_img)

    def pageset_select_first_img_confirm(self):
        self.base_click_element(page.person_modify_confim)

    # 业务组合方法：更改头像
    def pageset_touxiang(self):
        self.pageset_click_person()
        self.pageset_click_change_touxiang()
        self.pageset_click_select_touxiang_from_album()
        try:
            self.pageset_click_select_agree()
            self.pageset_click_change_touxiang()
            self.pageset_click_select_touxiang_from_album()
        except:
            pass
        self.pageset_select_first_img()
        self.pageset_select_first_img_confirm()

    def pageset_click_username(self):
        self.base_click_element(page.person_username)

    def pageset_input_new_username(self, username):
        self.base_input_value(page.person_username_input, username)

    def pageset_input_save(self):
        self.base_click_element(page.person_username_save)

    def pageset_click_username_back_btn(self):
        self.base_click_element(page.person_username_back)

    def pageset_get_new_username(self):
        return self.base_get_element_text(page.person_username)

    # 业务组合方法，更改用户名
    def pageset_new_username(self, username):
        self.pageset_click_person()
        self.pageset_click_username()
        self.pageset_input_new_username(username)
        sleep(1)
        self.pageset_input_save()
        sleep(1)
        self.pageset_click_username_back_btn()

    def pageset_click_change_gender(self):
        self.base_click_element(page.person_gender)

    def pageset_click_male_gender(self):
        self.base_click_element(page.person_gender_male)

    def pageset_get_new_gender(self):
        return self.base_get_element_text(page.person_gender)

    def pageset_return_to_setpage_keycode(self):
        for a in range(10):
            log.info(f'正在返回设置页面，第{a + 1}次尝试')
            if self.base_if_element_exist(page.setting_logout):
                break
            else:
                self.driver.press_keycode(4)

    # 消息推送通知
    def pageset_click_setting_notice(self):
        self.base_click_element(page.setting_notice)

    def pageset_click_app_tanchuang_tongzhi(self):
        self.base_click_element(page.app_tanchuang_tongzhi)

    # 清理缓存
    def pageset_click_ql_huancun(self):
        self.base_click_element(page.ql_huancun)

    def pageset_get_ql_huancun_reasult(self):
        return self.base_get_element_text(page.ql_huancun_0b)

    # 账号安全
    def pageset_click_zh_anquan(self):
        self.base_click_element(page.zh_anquan)

    def pageset_click_sq_zhuxiao_zhanghao(self):
        self.base_click_element(page.sq_zhuxiao_zhanghao)

    def pageset_get_zd_wangxiao_title(self):
        return self.base_if_element_exist(page.zh_anquan_if_success)

    # 关于早道

    def pageset_click_about_wsy(self):
        self.base_click_element(page.setting_about)

    def pageset_click_about_zaodao(self):
        self.base_click_element(page.about_zaodao)

    def pageset_get_about_zaodao_title(self):
        return self.base_get_element_text(page.about_zaodao_title)

    def pageset_get_about_wsy_phone_num(self):
        return self.base_get_element_text(page.about_tel)

